import type { WmsStockIn, WmsStockInDetail } from "@/pages/wms/stockIn/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
	//入库单编码
	code?: string;
	//来源单号
	sourceCode?: string;
	//入库单类型
	type?: string;
	//当前页码
	page: number;
	//每页数量
	pageSize: number;
}

export interface PageListRes {
	//总记录数
	total: number;
	//数据列表
	records: WmsStockIn[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
	apiClient.post({
		url: "/wms/stockIn/pageList",
		data,
	});
const getInfo = (id: React.Key): Promise<WmsStockIn> =>
	apiClient.get({
		url: `/wms/stockIn/${id}`,
	});

const add = (data: WmsStockIn): Promise<WmsStockIn> =>
	apiClient.post({
		url: "/wms/stockIn",
		data,
	});

const update = (data: WmsStockIn): Promise<WmsStockIn> =>
	apiClient.put({
		url: "/wms/stockIn",
		data,
	});

const remove = (ids: React.Key[]): Promise<void> =>
	apiClient.delete({
		url: "/wms/stockIn",
		params: {
			ids: ids.join(","),
		},
	});
const getstockInDetails = (id: React.Key): Promise<WmsStockInDetail[]> =>
	apiClient.post({
		url: "/wms/stockIn/detail/list",
		data: {
			stockInId: id,
		},
	});

export const wmsStockInService = {
	pageList,
	getInfo,
	add,
	update,
	remove,
	getstockInDetails,
};

export default wmsStockInService;
